let utility = require('./utility');

class GCD{

    /*
    辗转相除法求两个数的最大共约数。输入两个正整数， 输出两数的最大公约数
    */
    devisionAlgorithm(){
        if(arguments.length != 2){
            throw Error('Wrong arguments count');
        }
        let firstNum = parseInt(arguments[0], 10);
        let secondNum = parseInt(arguments[1], 10);
        if (isNaN(firstNum) || isNaN(secondNum)) {
            throw Error("illegal parameter");
        }
    
        let maxNum = utility.maxNumber(firstNum, secondNum);
        let minNum = utility.minNumber(firstNum, secondNum);

        if (minNum == 0) {
            return maxNum;
        }
        return devisionAlgorithm(minNum, maxNum % minNum);
    }
}


module.exports = new GCD();